package risk.control.application.component.loadview;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.LinearInterpolator;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import risk.control.application.R;


/**
 * CreationTime:2018/6/29
 * Describe:
 * Author:hm
 **/

public class CycleLoadView extends LinearLayout {

    private ImageView mIvLoad;
    private TextView mTvDes;
    private Animation mOperatingAnim;
    private final Context mContext;

    public CycleLoadView(Context context) {
        super(context);
        mContext = context;
        initView(context);
    }

    public CycleLoadView(Context context, AttributeSet attrs) {
        super(context, attrs);
        mContext = context;
        initView(context);
    }

    public CycleLoadView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        mContext = context;
        initView(context);
    }

    private void initView(Context context) {
        View loadView = View.inflate(context, R.layout.cycle_load_view, this);
        mIvLoad = loadView.findViewById(R.id.iv_load);
        mTvDes = loadView.findViewById(R.id.tv_des);
        initAnimation();
    }

    private void initAnimation() {
        mOperatingAnim = AnimationUtils.loadAnimation(mContext, R.anim.rotating);
        mOperatingAnim.setFillAfter(true);
        mOperatingAnim.setInterpolator(new LinearInterpolator());
    }

    public void showLoad() {
        if (mOperatingAnim != null) {
            mIvLoad.startAnimation(mOperatingAnim);
        }
    }

    public void setDes(String des) {
        mTvDes.setText(des);
    }

    public void stopLoad() {
        mIvLoad.clearAnimation();
    }


}
